package com.wyw.base.comm;


import org.springframework.http.HttpEntity;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wyw.core.workflow.service.support.WorkFlowTask;



@Controller 
public class TaskList {
	 
	 
	@RequestMapping(value = "/queryTaskList.biz",method=RequestMethod.GET)//
	public String queryTaskList(Model model){
		System.out.println("登录成功");
		String taskView="helloTaskList";
		return taskView;
	}
	
	
	@RequestMapping(value = "/queryTestAjaxTaskList.biz",method=RequestMethod.GET)//
	public String queryTestAjaxTaskList(Model model){
		String taskView="testTaskList";
		return taskView;
	}
	
	

	@RequestMapping(value = "/sendAjaxPostM0.biz",method=RequestMethod.POST,produces={})
	@ResponseBody
	public  WorkFlowTask sendAjaxPostM0(HttpEntity<LinkedMultiValueMap> requestInfo ,Model model)throws Exception{
		System.out.println("sendAjaxPostM1..bizTypeCode:"+requestInfo.getBody());
		WorkFlowTask workFlowTask = new WorkFlowTask();
		workFlowTask.setBizTypeCode("xxxxxxx");
		return workFlowTask;
	}
		
 
	
	
	
	/**
	 * 
	 * 
	 * --------------------------------------
	 <tr>
		<td align="right">bizTypeCode:</td>
		<td align="left"><input type="text" id="workFlowTask/bizTypeCode" name="bizTypeCode" value="10001"></td>
	</tr>
	  
	 * --------------------------------------
	 function sendAjaxPost4(){
		var postData = $("#inputform").serialize() ;
		alert(postData);
		jQuery.ajax({
			type:"POST",
			cache:false,
			url:"/spring-web/sendAjaxPostM4.biz",
			data:postData,
			success:function(data){
				if(isAjaxSucess(data)){
					alert("ok"+data.bizTypeCode);
				}
			},
			error:function(XMLHttpRequest,textStatus,errorThrown){
				alert("error"+XMLHttpRequest.responseText);
				//alert(JSON.parse(errorThrown));
			}
		});
	}
	 *---------------------------------------
	 * **/
	@RequestMapping(value = "/sendAjaxPostM4.biz",method=RequestMethod.POST)
	@ResponseBody
	public  WorkFlowTask sendAjaxPostM4(@ModelAttribute WorkFlowTask workFlowTask ,Model model)throws Exception{
		System.out.println("sendAjaxPostM1..bizTypeCode:"+workFlowTask.getBizTypeCode());
		return workFlowTask;
	}
	
	 

	
	
	
	/***
	 * post提交参数 ajax	,非json方式与普通的form提交一样。
	 * 
	 * 不需要 设定contentType:"",dataType:"",
	 *------------------------------------------------------
	 function sendAjaxPost1(){
		var postData = $("#inputform").serialize() ;
		alert(postData);
		jQuery.ajax({
			type:"POST",
			cache:false,
			url:"/spring-web/sendAjaxPostM1.biz",
			data:postData,
			success:function(data){
				if(isAjaxSucess(data)){
					alert("ok"+data.bizTypeCode);
				}
			},
			error:function(XMLHttpRequest,textStatus,errorThrown){
				alert("error"+XMLHttpRequest.responseText);
				//alert(JSON.parse(errorThrown));
			}
		});
	}
	
	//--------------------------------------------------------------
	 * @ResponseBody对的jackson对象必须是有get set 方法对应的java bean类型
	*---------------------------------------------------------------
	 */
	@RequestMapping(value = "/sendAjaxPostM1.biz",method=RequestMethod.POST)
	@ResponseBody
	public  WorkFlowTask sendAjaxPostM1(@ModelAttribute("bizTypeCode") String bizTypeCode ,Model model)throws Exception{
		System.out.println("sendAjaxPostM1..bizTypeCode:"+bizTypeCode);
		WorkFlowTask workFlowTask = new WorkFlowTask();
		workFlowTask.setBizTypeCode("xxxxxxx");
		return workFlowTask;
	}
	
	/**
	 * @RequestBody json提交
	 * post提交参数 ajax	,在requestMapping 中不设定",produces={MediaType.APPLICATION_JSON_VALUE}
	 * 
	*-------------------------------------------------------------------
	//var str=JSON.stringfy(obj);
	function sendAjaxPost3(){
		jQuery.ajax({
			type:"POST",
			cache:false,
			url:"/spring-web/sendAjaxPostM3.biz",
			contentType:"application/json",
			dataType:'json',//这里一定是‘json’,不是'application/json',
			data:JSON.stringify({bizTypeCode:'10001'}),
			success:function(data){
				if(isAjaxSucess(data)){
					alert("ok"+data.bizTypeCode);
				}
			},
			error:function(XMLHttpRequest,textStatus,errorThrown){
			//alert(XMLHttpRequest.getAllResponseHeaders());
			alert(XMLHttpRequest.responseText);
			//alert(XMLHttpRequest.responseXML.xml);
				// alert(typeof(XMLHttpRequest))
				//alert(JSON.parse(errorThrown));
			}
		});
	}
	
	*----------------------------------------------
	*/
	@RequestMapping(value = "/sendAjaxPostM3.biz",method=RequestMethod.POST ,produces={MediaType.APPLICATION_JSON_VALUE})//	
	@ResponseBody
	public  String sendAjaxPostM3(@RequestBody WorkFlowTask  workFlowTask,Model model)throws Exception{
		System.out.println("sendAjaxPostM3..workFlowTask.bizTypeCode:"+workFlowTask.getBizTypeCode());
		 
		return workFlowTask.getBizTypeCode();
	}
	
	
	/*@测试通过
	 * post提交参数 ajax	
	 * js:
	 * 
	 * //var str=JSON.stringfy(obj);
	//'{"bizTypeCode":"10001"}',
		function sendAjaxPost2(){
	 
		var inputformObj=$("#inputform").serialize();
		var postData={bizTypeCode:'10001'};
		alert(JSON.stringify(postData));
		jQuery.ajax({
			type:"POST",
			cache:false,
			url:"/spring-web/sendAjaxPostM2.biz",
			contentType:"application/json;charset=UTF-8",
			dataType:'json',
			data:JSON.stringify(postData),
		});
	}
	 * @param workFlowTask
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/sendAjaxPostM2.biz",method=RequestMethod.POST)//	
	@ResponseBody
	public  String sendAjaxPostM2(@RequestBody  WorkFlowTask  workFlowTask,Model model)throws Exception{
		System.out.println("sendAjaxPostM2..bizTypeCode:"+workFlowTask.getBizTypeCode());
		 
		return workFlowTask.getBizTypeCode();
	}
	
	
	
	
	/*
	 * @测试通过：ajax get提交参数
	 * */
	//ajax 用@RequestParam("userId")请示参数userId到变量userId,返回jackson
	@RequestMapping(value = "/sendAjaxGet.biz",method=RequestMethod.GET)//	
	@ResponseBody
	@Transactional(propagation=Propagation.REQUIRED,rollbackFor=Exception.class,readOnly=false)
	public  String sendAjaxGet(@RequestParam("userId") String userId)throws Exception{
		System.out.println("userId:" + userId);
		
		//测试用户安全信息
		return "";
	}
		
		
		
	/*
	 * @测试通过：post提交参数
	 * */
	@RequestMapping(value = "/sendPost.biz",method=RequestMethod.POST)//	
	public  String sendPost(@ModelAttribute("userId") String userId)throws Exception{
		if(userId !=null){
			System.out.println("userId:"+userId);
			//throw  new WYWException("现在测试下异常");
		}
		return "testTaskList";
	}
	
	
}
